package com.tronsis.distribution.biz.impl;

import android.app.Activity;

import com.google.gson.reflect.TypeToken;
import com.tronsis.distribution.bean.CourseBean;
import com.tronsis.distribution.bean.CourseDetailBean;
import com.tronsis.distribution.bean.TeamTrainerBean;
import com.tronsis.distribution.biz.TeamBiz;
import com.tronsis.distribution.http.Url;
import com.tronsis.library.http.HttpCallBack;
import com.tronsis.library.http.ListBean;
import com.tronsis.library.http.RequestClient;
import com.tronsis.library.http.RequestMethod;
import com.tronsis.library.http.UICallBack;


public class TeamBizImpl implements TeamBiz {
    @Override
    public void listMyCourse(Activity activity, int page, int size, String search,final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size),"search",search).excute(RequestMethod.GET, Url.COURSE);
    }

    @Override
    public void deleteMyCourse(Activity activity, String myCourseId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.DELETE, Url.COURSE + "/" + myCourseId);
    }

    @Override
    public void listMyTrainer(Activity activity, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<TeamTrainerBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.MY_TRAINER);
    }

    @Override
    public void getCourseDetail(Activity activity, String courseId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, CourseDetailBean.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.GET, Url.COURSE_DETAIL + "/" + courseId);
    }

    @Override
    public void listTeamTrainer(Activity activity, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<TeamTrainerBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.TRAINER_AGENT);
    }

    @Override
    public void listTeamAgent(Activity activity, String level, String role, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<TeamTrainerBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("level", level, "role", role, "page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.TRAINER_AGENT);
    }

    @Override
    public void listTeamCourse(Activity activity, boolean onlyMime, int page, int size, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams("onlyMime", String.valueOf(onlyMime), "page", String.valueOf(page), "size", String.valueOf(size)).excute(RequestMethod.GET, Url.TRAINER_COURSE);
    }

    @Override
    public void uploadCourse(Activity activity, String name, String description, String imageFid, String videoFid, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("name", name, "description", description, "imageFid", imageFid, "videoFid", videoFid).excute(RequestMethod.POST, Url.TRAINER_COURSE);

    }

    @Override
    public void editCourse(Activity activity, String courseId, String name, String description, String imageFid, String videoFid, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("name", name, "description", description, "imageFid", imageFid, "videoFid", videoFid).excute(RequestMethod.POST, Url.TRAINER_COURSE + "/" + courseId);


    }

    @Override
    public void deleteCourse(Activity activity, String courseId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, new TypeToken<ListBean<CourseBean>>() {
        }.getType()) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addGetParams().excute(RequestMethod.POST, Url.TRAINER_COURSE + "/" + courseId);

    }

    @Override
    public void pushMyCourse(Activity activity, String courseId, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter().excute(RequestMethod.POST, Url.TRAINER_COURSE + "/" + courseId + "/push");

    }

    @Override
    public void pushNotice(Activity activity, String content, String level, String role, final UICallBack callBack) throws Exception {
        RequestClient.getInstance(new HttpCallBack(activity, String.class) {
            @Override
            public void onStart() {
                callBack.onStart();
            }

            @Override
            public void onCallBack(int status, Object result) {
                switch (status) {
                    case 200:
                        callBack.onRefresh(result);
                        break;
                    default:
                        callBack.onFailure(status);
                        break;
                }
            }
        }).addParameter("content", content, "level", level, "role", role).excute(RequestMethod.POST, Url.TRAINER_NOTICE);
    }


}
